{% extends "wiki/base.html" %}
{% from "includes/common_macros.html" import for_contributors_sidebar %}
{% from "layout/errorlist.html" import errorlist %}
{% from "includes/common_macros.html" import content_editor with context %}
{% from "wiki/includes/document_macros.html" import submit_revision %}
{% set title = _('Create a New Article | Knowledge Base') %}
{# TODO: Change KB url to landing page when we have one #}
{% set crumbs = [(None, _('New Article'))] %}
{% set classes = 'new' %}
{% set styles = ('wiki', 'wiki-editor', 'jqueryui') %}
{% set scripts = ('wiki', 'wiki.editor', 'jqueryui') %}

{% block content %}
  <div class="grid_9">
    <article id="edit-document">
      <h1>{{ _('Create a New Knowledge Base Article') }}</h1>
      <div id="document-form">
        {{ errorlist(document_form) }}
        {{ errorlist(revision_form) }}
        <form action="" method="post" data-json-url="{{ url('wiki.json') }}">
          {% csrf_token %}
          <ul>
            {% for field in document_form.visible_fields() if (field.name != 'is_localizable' or settings.WIKI_DEFAULT_LANGUAGE == request.LANGUAGE_CODE) %}
              <li>{{ field|label_with_help }}{{ field|safe }}</li>
            {% endfor %}
          </ul>
          <ul>
            {% for field in revision_form.visible_fields() %}
              <li>
                {% if field.name not in ['comment', 'content'] %}
                  {{ field|label_with_help }}{{ field|safe }}
                {% elif field.name == 'content' %}
                  {{ revision_form.content.label_tag()|safe }}
                  {{ content_editor(revision_form.content) }}
                {% endif %}
                {% if field.name == 'summary' %}
                  <p><span id="remaining-characters">{{ field.field.max_length }}</span> {{ _('characters remaining.') }}</p>
                {% endif %}
              </li>
            {% endfor %}
          </ul>
          {{ revision_form.hidden_fields()|join|safe }}
          {{ submit_revision(revision_form) }}
        </form>
      </div>
      <div id="preview"></div>
    </article>
  </div>

  <script type="application/json" class="showfor-data">
    {{ showfor_data(products) }}
  </script>
{% endblock %}

{% block side_top %}
  <nav id="doc-tools">
    <ul class="sidebar-nav sidebar-folding">
      {{ for_contributors_sidebar(user, settings.WIKI_DEFAULT_LANGUAGE, True) }}
    </ul>
  </nav>
{% endblock %}
